package com.shirley.thread;

import java.util.Random;

public class ShirleyTask implements Runnable {

    String label;

    public ShirleyTask(String label) {
        this.label = label;
    }

    @Override
    public void run() {
        System.out.println(label + " is running...");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(label + " is done.");

    }

    public static void main(String[] args) throws InterruptedException {
        ShirleyTask task1 = new ShirleyTask("Task1");
        ShirleyTask task2 = new ShirleyTask("Task2");
        Thread t1 = new Thread(task1);
        Thread t2 = new Thread(task2);
        t1.start();
        t2.start();

        while (t1.isAlive() || t2.isAlive()) {
            System.out.println(task1.label + " is " + t1.getState());
            System.out.println(task2.label + " is " + t2.getState());
            Thread.sleep(1000L);
        }
    }
}
